package com.smart.community.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;

/**
 * 日志监控配置
 * 
 * @author Wu.Liang
 * @since 2025-01-30
 */
@Configuration
public class LogMonitorConfig {
    
    /**
     * 配置定时切面，用于监控方法执行时间
     */
    @Bean
    public TimedAspect timedAspect(MeterRegistry registry) {
        return new TimedAspect(registry);
    }
    
    /**
     * 系统日志查询性能监控
     */
    @Bean("systemLogQueryTimer")
    public Timer systemLogQueryTimer(MeterRegistry registry) {
        return Timer.builder("system.log.query.duration")
            .description("系统日志查询耗时")
            .publishPercentiles(0.5, 0.95, 0.99) // 50%, 95%, 99%分位数
            .publishPercentileHistogram()
            .register(registry);
    }
    
    /**
     * 登录日志查询性能监控
     */
    @Bean("loginLogQueryTimer")
    public Timer loginLogQueryTimer(MeterRegistry registry) {
        return Timer.builder("login.log.query.duration")
            .description("登录日志查询耗时")
            .publishPercentiles(0.5, 0.95, 0.99) // 50%, 95%, 99%分位数
            .publishPercentileHistogram()
            .register(registry);
    }
    
    /**
     * 日志导出性能监控
     */
    @Bean("logExportTimer")
    public Timer logExportTimer(MeterRegistry registry) {
        return Timer.builder("log.export.duration")
            .description("日志导出耗时")
            .publishPercentiles(0.5, 0.95, 0.99) // 50%, 95%, 99%分位数
            .publishPercentileHistogram()
            .register(registry);
    }
}
